<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class AccountResource extends JsonResource
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        $roles = $authrations = [];
        foreach ($this->roles as $role){
            $roles[] = RoleResource::make($role->info);
            $authrations = array_merge($authrations,json_decode($role->info->authrations,1));
        }
        return [
            'id' => $this->id,
            'username' => $this->username,
            'realname' => $this->realname,
            'roles' => $roles,
            'authrations' => $authrations
        ];
    }
}
